#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T,n,ans,k,t[1000009];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&T);
    while(T--)
    {
        scanf("%lld",&n);
        for(ll i=1;i<=n;i++)
        {
            scanf("%lld",&k);
            t[k]++;
        }
        for(ll i=1;i<=1000009;i++)
        {
            if(t[i]>=2)
            ans+=(t[i]-1)*i;
            t[i]=0;
        }
        cout<<ans<<endl;
        ans=0;
    }
}